package logic

import (
	"context"
	"mall/services/distributed-id/rpc/internal/svc"
	"mall/services/distributed-id/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetIdLogic {
	return &GetIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetIdLogic) GetId(in *pb.IdReq) (*pb.IdResp, error) {
	useCase := l.svcCtx.SegmentUseCase
	out := &pb.IdResp{}
	id, err := useCase.GetId(l.svcCtx.DBEngin, in.Tag)
	if err != nil {
		return nil, err
	}
	out.Id = id
	return out, nil
}
